package com.company.userRegister.validation;

import java.util.regex.Pattern;

public class UserValidator {

    private static final Pattern EMAIL_PATTERN = Pattern.compile(
            "^[A-Za-z0-9+_.-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$"
    );

    // 验证用户名
    public static void validateUsername(String username) {
        if (username == null || username.trim().isEmpty()) {
            throw new IllegalArgumentException("用户名不能为空！");
        }
    }

    // 验证 email
    public static void validateEmail(String email) {
        if (email == null || !EMAIL_PATTERN.matcher(email).matches()) {
            throw new IllegalArgumentException("email格式错误！");
        }
    }

    // 验证密码
    public static void validatePassword(String password) {
        if (password == null || password.length() < 6 || password.trim().isEmpty()) {
            throw new IllegalArgumentException("密码至少为非空格的6位！");
        }
    }
}
